package ooday04;

import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ;

import java.awt.font.FontRenderContext;

public class AnimalTesting {
    public static void main(String[] args) {

//        Animal []animal = new Animal[5];
//        animal[0]=new Dog("大黄狗",2,"黄色");
//        animal[1] = new Fish("大金鱼", 8, "金色");
//        animal[2] = new Chick("大红鸡",3,"红色");
//        animal[3] = new Chick("大金鱼2", 8, "金色");
//        animal[4]=new Dog("大黄狗2",2,"黄色");
//        for (int i=0;i<animal.length;i++){
//            animal[i].eat();
//            animal[i].drink();
//            if (animal[i]instanceof Dog){
//                Dog D=(Dog) animal[i];
//                D.special();
//                D.special();
//            }
//            if (animal[i]instanceof Fish){
//                Fish F=(Fish)animal[i];
//                F.swim();
//
//            }
//            if (animal[i]instanceof Chick){
//                Chick C=(Chick) animal[i];
//                C.layEggs();
//            }
//            if (animal[i] instanceof Swim){
//                Swim S=(Swim) animal[i];
//                S.swim();
//            }
//        }




        Animal []animals=new Animal[5];
        animals[0]=new Dog("大黄狗",2,"黄色");
        animals[1]=new Fish("大金鱼", 8, "金色");
        animals[2]=new Chick("大红鸡",3,"红色");
        animals[3]=new Dog("大黄狗2",4,"黄色");
        animals[4]=new Fish("大金鱼2", 6, "金色");
        for (int i=0;i<animals.length;i++){
            animals[i].eat();
            animals[i].drink();


            if (animals[i]instanceof Dog) {
                //用instanceof判断强转是否成功，若成功则向下造型
                Dog dog=(Dog)animals[i];
                dog.special();

            }

            if (animals[i]instanceof Fish){
                Fish fish=(Fish) animals[i];


            }
            if (animals[i]instanceof Chick){
                Chick C=(Chick) animals[i];
                C.layEggs();
            }
            if (animals[i]instanceof Swim){
                Swim S=(Swim) animals[i];
                S.swim();
            }


        }


        master master = new master();
        Dog dog = new Dog("大黄狗",2,"黄色");
        Fish fish = new Fish("大金鱼", 8, "金色");
        Chick chick = new Chick("大红鸡",3,"红色");
        master.fly(dog);
        master.fly(fish);
        master.fly(chick);
        dog.special();//调用狗独特方法
        chick.layEggs();//调用鸡独特方法
        dog.swim();
        fish.swim();




//        master master = new master();
//        Dog dog = new Dog("大黄狗",2,"黄色");
//        Fish fish = new Fish("大金鱼", 8, "金色");
//        Chick chick = new Chick("大红鸡",3,"红色");
//        master.raise(dog);//调用有参方法时候，系统自动做了向上造型
//        //把超类的当做参数或返回值类型，传递派生对象，扩大使用范围：实现代码复用
//        master.raise(fish);
//        master.raise(chick);
//        dog.special();
//        dog.swim();
//        fish.swim();
//        chick.layEggs();





















    }
}
